package kr.co.nothingboard.admin.controller;

import java.util.List;
import java.util.Locale;

import kr.co.nothingboard.module.board.model.*;
import kr.co.nothingboard.module.board.service.BoardService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/admin/board")
public class BoardController {
	
	@Autowired
	BoardService boardService;
	
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String boardList(BoardSearchDto dto, Locale locale, Model model) throws Exception {

		model.addAttribute("boardList", boardService.getBoardList(dto));
		
		return "admin/board/board_list";
	}
	@RequestMapping(value = "/form", method = RequestMethod.GET)
	public String boardForm(BoardSearchDto dto, Locale locale, Model model) throws Exception {

		return "admin/board/board_form";
	}
	
	@RequestMapping(value = "/category/list", method = RequestMethod.GET)
	public String boardCategoryList(BoardSearchDto dto, Locale locale, Model model) throws Exception {
		
		dto.setBoardNo(1);
		dto.setCategoryUpNo(0);

		model.addAttribute("categoryList", boardService.getBoardCategoryList(dto));
		
		return "admin/board/board_category_list";
	}
	
	@RequestMapping(value = "/category/sub/list", method = RequestMethod.POST, headers="Accept=application/json")
	public @ResponseBody List<BoardCategoryVo> boardCategorySubList(@RequestBody BoardSearchDto dto, 
			Locale locale) throws Exception {

		return boardService.getBoardCategoryList(dto);
	}

}
